package game.DecuryMan
{
	/**
	 * @author LeeXiangwei
	 * @date 2013.2.16
	 * @since v1.0
	 * 棋子形成棋堆，吃棋的规则。
	 */
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	import mx.containers.Grid;
	import mx.controls.Alert;
	import mx.managers.PopUpManager;
	
	import org.osmf.utils.URL;
	
	[SWF(width="60",height="60")]
	public class DecuryMan extends Sprite
	{
		
		private var img:Loader = new Loader();
		
		public var row:int;  //所在行
		public var col:int; //所在列
		public var pos:int; //该棋子的位置
		public var index:int; // 棋子数组中的索引
		public var level:int; // 棋子的等级
		private var _isCross:Boolean;			//长距离十字移动	
		private var _isCrossAttack:Boolean;	//长距离十字攻击
		private var _isBias:Boolean;			//长距离斜方向移动
		private var _isBiasAttack:Boolean;		//长距离斜方向攻击
		
		public var _moveFlag:Boolean;
		
		public static const scale:Number = 0.6;
		
		public function DecuryMan()
		{
			super();
		}
		
		//初始化棋子的移动规则
		public function initial(isCross:Boolean,isCrossAttack:Boolean,isBias:Boolean,isBiasAttack:Boolean,moveFlag:Boolean):void
		{
			_isCross=isCross;
			_isCrossAttack=isCrossAttack;
			_isBias=isBias;
			_isBiasAttack=isBiasAttack;
			_moveFlag=moveFlag;
		}

		public function  moveFlag(flag:Boolean):void
		{
			_moveFlag=flag;
		}

		public function get isCross():Boolean
		{
			return _isCross;
		}
		public function get isCrossAttack():Boolean
		{
			return _isCrossAttack;
		}
		public function get isBias():Boolean
		{
			return _isBias;
		}
		public function get isBiasAttack():Boolean
		{
			return _isBiasAttack;
		}
		
		
		
		private function up(ev:MouseEvent):void
		{
			for(var i:int=0;i<100;i++)
			{
				var greenPointRow:int=i/10;
				var greenPointCol:int=i%10;
				if(parent.contains(ChessMain.greenPoints[greenPointRow][greenPointCol]))
				{
					parent.removeChild(ChessMain.greenPoints[greenPointRow][greenPointCol]);
				}			
			}
		}
		private function down(evt:MouseEvent):void
		{
			showGreenPoints(this);
		}
		
		//点击棋子事件
		public function click(evt:MouseEvent):void{
			parent.addChild(this);
			if(ChessMain.selectedDecuryman == this){
				evt.stopPropagation();
				return;
			}
			else if(null==ChessMain.selectedDecuryman&&true==this._moveFlag)
			{
				//如果还没有选中一个棋子  或者 选中的棋子是棋堆中的 另一个棋子
				//			if(ChessMain.selectedDecuryman == null || this.pos == ChessMain.selectedDecuryman.pos){
				
				//如果没有还没有选中一个棋子，就选中一个棋子
				ChessMain.selectedDecuryman = this;
				ChessMain.showSelected.x = this.x;
				ChessMain.showSelected.y = this.y;			
				ChessMain.showSelected.scaleX = this.scaleX;
				ChessMain.showSelected.scaleY = this.scaleY;				
				parent.addChild(ChessMain.showSelected);				
			}
			else if(ChessMain.selectedDecuryman.level*this.level<0&&ChessMain.mapArr[this.row][this.col]<100&&true==ChessMain.selectedDecuryman._moveFlag)
			{
				if(passJudge(ChessMain.selectedDecuryman,this.col,this.row))
				{
					ChessMain.selectedDecuryman.x = this.col * ChessMain.gridW;
					ChessMain.selectedDecuryman.y = this.row * ChessMain.gridW;			
					ChessMain.selectedDecuryman.pos = this.row*10 + this.col;				
					ChessMain.selectedDecuryman.scaleX = 1;
					ChessMain.selectedDecuryman.scaleY = 1;					
					ChessMain.selectedDecuryman.moveFlag(false);
					for(var i:int=0;i<3;i++)
					{
						if(null!=ChessMain.lastMoveMan[i])
						{
							ChessMain.lastMoveMan[i].moveFlag(true);
							ChessMain.lastMoveMan[i]=null;
						}
					}
					ChessMain.lastMoveMan[0]=ChessMain.selectedDecuryman;
					//更新地图的数组
					ChessMain.mapArr[this.row][this.col] = ChessMain.selectedDecuryman.level;
					
					
					//说明是从棋堆 选了一个棋子. 需要把棋堆的另一个棋子恢复 正大小常。
					if(ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col] > 100 )
					{
						var i:int = ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col] / 100;
						var j:int = ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col] % 100;
						//var remainStack:int;
						if(i == ChessMain.selectedDecuryman.index)
							i = j;
						--i;			
						//manArr[i]就是棋堆 剩下的那个棋子
						ChessMain.manArr[i].x = ChessMain.selectedDecuryman.col * ChessMain.gridW;
						ChessMain.manArr[i].y = ChessMain.selectedDecuryman.row * ChessMain.gridW;
						ChessMain.manArr[i].scaleX = 1;
						ChessMain.manArr[i].scaleY = 1;					
						ChessMain.showSelected.scaleX = 1;
						ChessMain.showSelected.scaleY = 1;
						ChessMain.showSelected.x = ChessMain.manArr[i].x;
						ChessMain.showSelected.y = ChessMain.manArr[i].y;				
					}				
					//走棋后要更新该棋子  在棋盘上的坐标
					ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col]=0;
					ChessMain.selectedDecuryman.col = this.col;
					ChessMain.selectedDecuryman.row = this.row;				
					ChessMain.selectedDecuryman = null; //走完棋后 当前选择的棋子为null
					parent.removeChild(ChessMain.showSelected);
					if(this.level>0)
					{
						for(var iii:int=0;iii<10;iii++)
						{
							if(null==ChessMain.redDead[iii])
							{
								ChessMain.redDead[iii]=this;
								this.x=610;
								this.y=iii*70;
								this.removeEventListener(MouseEvent.CLICK,click);
								this.removeEventListener(MouseEvent.MOUSE_DOWN,down);
								this.removeEventListener(MouseEvent.MOUSE_UP,up);
								break;
							}
						}
					}
					if(this.level<0)
					{
						for(var jjj:int=0;jjj<10;jjj++)
						{
							if(null==ChessMain.blackDead[jjj])
							{
								ChessMain.blackDead[jjj]=this;
								this.x=680;
								this.y=jjj*70;
								this.removeEventListener(MouseEvent.CLICK,click);
								this.removeEventListener(MouseEvent.MOUSE_DOWN,down);
								this.removeEventListener(MouseEvent.MOUSE_UP,up);
								break;
							}
						}
					}
					//	parent.removeChild(this);
				}
				else 
				{
					ChessMain.selectedDecuryman=null;
					parent.removeChild(ChessMain.showSelected);
				}
			}
			else if(ChessMain.selectedDecuryman.level*this.level>0&&this.pos != ChessMain.selectedDecuryman.pos&&ChessMain.mapArr[this.row][this.col]<100&&true==ChessMain.selectedDecuryman._moveFlag)
			{
				if(passJudge(ChessMain.selectedDecuryman,this.col,this.row))
				{
					
					ChessMain.selectedDecuryman.scaleX = scale;
					ChessMain.selectedDecuryman.scaleY = scale;
					
					ChessMain.selectedDecuryman.x = (1-scale) * ChessMain.gridW + this.x;
					ChessMain.selectedDecuryman.y = (1-scale) * ChessMain.gridW + this.y;
					
					this.scaleX = scale;
					this.scaleY = scale;
					
					if(this.level>0)
					{
						lakeJudge(-2,this.row-1,this.col);
						lakeJudge(-2,this.row,this.col-1);
						lakeJudge(-2,this.row+1,this.col);
						lakeJudge(-2,this.row,this.col+1);
						mountainJudge(2,this.row,this.col);
					}
					if(this.level<0)
					{
						lakeJudge(-3,this.row-1,this.col);
						lakeJudge(-3,this.row,this.col-1);
						lakeJudge(-3,this.row+1,this.col);
						lakeJudge(-3,this.row,this.col+1);
						mountainJudge(3,this.row,this.col);	
					}
					
					for(var i:int=0;i<3;i++)
					{
						if(null!=ChessMain.lastMoveMan[i])
						{							
							ChessMain.lastMoveMan[i].moveFlag(true);
							ChessMain.lastMoveMan[i]=null;
						}
					}
					ChessMain.selectedDecuryman.moveFlag(false);
					this.moveFlag(false);
					ChessMain.lastMoveMan[1]=ChessMain.selectedDecuryman;
					ChessMain.lastMoveMan[2]=this;
					//第一种方法，直接用6代表棋堆
					//ChessMain.mapArr[this.row][this.col] = 6;
					ChessMain.mapArr[this.row][this.col] = index*100 + ChessMain.selectedDecuryman.index;
					//					Alert.show(ChessMain.mapArr[this.row][this.col]+ " a");
					//					Alert.show(ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col]+" b");
					//说明是从棋堆 选了一个棋子. 需要把棋堆的另一个棋子恢复 正大小常。
					if(ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col] > 100 )
					{
						var i:int = ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col] / 100;
						var j:int = ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col] % 100;
						//var remainStack:int;
						if(i == ChessMain.selectedDecuryman.index)
							i = j;
						--i;			
						//manArr[i]就是棋堆 剩下的那个棋子
						ChessMain.manArr[i].x = ChessMain.selectedDecuryman.col * ChessMain.gridW;
						ChessMain.manArr[i].y = ChessMain.selectedDecuryman.row * ChessMain.gridW;
						ChessMain.manArr[i].scaleX = 1;
						ChessMain.manArr[i].scaleY = 1;					
						ChessMain.showSelected.scaleX = 1;
						ChessMain.showSelected.scaleY = 1;
						ChessMain.showSelected.x = ChessMain.manArr[i].x;
						ChessMain.showSelected.y = ChessMain.manArr[i].y;	
						ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col]=ChessMain.manArr[i].level;
						ChessMain.selectedDecuryman.pos = this.pos;
						ChessMain.selectedDecuryman.row = pos/10;
						ChessMain.selectedDecuryman.col = pos%10;					
						ChessMain.selectedDecuryman = null; //走完棋后 当前选择的棋子为null
						parent.removeChild(ChessMain.showSelected);
					}	
					else {
						//走棋后要更新该棋子  在棋盘上的坐标
						//					ChessMain.selectedDecuryman.col = this.col;
						//					ChessMain.selectedDecuryman.row = this.row;
						ChessMain.mapArr[ChessMain.selectedDecuryman.row][ChessMain.selectedDecuryman.col]=0;
						ChessMain.selectedDecuryman.pos = this.pos;
						ChessMain.selectedDecuryman.row = pos/10;
						ChessMain.selectedDecuryman.col = pos%10;					
						ChessMain.selectedDecuryman = null; //走完棋后 当前选择的棋子为null
						parent.removeChild(ChessMain.showSelected);
					}
					for(var ii:int=0;ii<100;ii++)
					{
						for(var jj:int=0;jj<100;jj++)
							ChessMain.terrianJudge[ii][jj]=0;
					}
				}
				else 
				{
					ChessMain.selectedDecuryman=null;
					parent.removeChild(ChessMain.showSelected);
				}
			}
			/*
			else{  //如果已经选中了棋子
			
			//先判断下点击的位置是不是就是当前棋子的位置
			if(this.pos != ChessMain.selectedDecuryman.pos){
			ChessMain.selectedDecuryman.scaleX = scale;
			ChessMain.selectedDecuryman.scaleY = scale;
			
			ChessMain.selectedDecuryman.x = (1-scale) * ChessMain.gridW + this.x;
			ChessMain.selectedDecuryman.y = (1-scale) * ChessMain.gridW + this.y;
			
			this.scaleX = scale;
			this.scaleY = scale;
			
			ChessMain.selectedDecuryman.pos = this.pos;
			ChessMain.selectedDecuryman.row = pos/10;
			ChessMain.selectedDecuryman.col = pos%10;
			
			//第一种方法，直接用6代表棋堆
			//ChessMain.mapArr[this.row][this.col] = 6;
			ChessMain.mapArr[this.row][this.col] = index*100 + ChessMain.selectedDecuryman.index;
			ChessMain.selectedDecuryman = null;
			
			}
			
			}
			*/
			evt.stopPropagation();
		}
		
		private function mountainJudge(flag:int,row:int,column:int):void
		{
			if(ChessMain.terrian[row][column]<=0) return;
			else if(0==ChessMain.terrianJudge[row][column])
			{
				ChessMain.terrian[row][column]=flag;
				ChessMain.terrianJudge[row][column]=1;
				if(2==flag)
				{
					var redOwn:RedOwn=new RedOwn();
					redOwn.x=column*ChessMain.gridW;
					redOwn.y=row*ChessMain.gridW;
					parent.addChild(redOwn);
					ChessMain.terrianFlag[row][column].x=column*ChessMain.gridW+20;
					ChessMain.terrianFlag[row][column].y=row*ChessMain.gridW+20;
					parent.addChild(ChessMain.terrianFlag[row][column]);
				}
				if(3==flag)
				{
					var blackOwn:BlackOwn=new BlackOwn();
					blackOwn.x=column*ChessMain.gridW;
					blackOwn.y=row*ChessMain.gridW;
					parent.addChild(blackOwn);
					ChessMain.terrianFlag[row][column].x=column*ChessMain.gridW+20;
					ChessMain.terrianFlag[row][column].y=row*ChessMain.gridW+20;
					parent.addChild(ChessMain.terrianFlag[row][column]);
				}
				mountainJudge(flag,row+1,column);
				mountainJudge(flag,row-1,column);
				mountainJudge(flag,row,column+1);
				mountainJudge(flag,row,column-1);
			}
			else return;
		}
		private function lakeJudge(flag:int,row:int,column:int):void
		{
			if(ChessMain.terrian[row][column]>=0)return;
			else if(0==ChessMain.terrianJudge[row][column])
			{
				ChessMain.terrian[row][column]=flag;
				ChessMain.terrianJudge[row][column]=1;
				if(-2==flag)
				{
					var redOwn:RedOwn=new RedOwn();
					redOwn.x=column*ChessMain.gridW;
					redOwn.y=row*ChessMain.gridW;
					parent.addChild(redOwn);
					ChessMain.terrianFlag[row][column].x=column*ChessMain.gridW+20;
					ChessMain.terrianFlag[row][column].y=row*ChessMain.gridW+20;
					parent.addChild(ChessMain.terrianFlag[row][column]);
				}
				if(-3==flag)
				{
					var blackOwn:BlackOwn=new BlackOwn();
					blackOwn.x=column*ChessMain.gridW;
					blackOwn.y=row*ChessMain.gridW;
					parent.addChild(blackOwn);
					ChessMain.terrianFlag[row][column].x=column*ChessMain.gridW+20;
					ChessMain.terrianFlag[row][column].y=row*ChessMain.gridW+20;
					parent.addChild(ChessMain.terrianFlag[row][column]);
				}
				lakeJudge(flag,row+1,column);
				lakeJudge(flag,row-1,column);
				lakeJudge(flag,row,column+1);
				lakeJudge(flag,row,column-1);
				lakeJudge(flag,row-1,column-1)
				lakeJudge(flag,row-1,column+1);
				lakeJudge(flag,row+1,column-1);
				lakeJudge(flag,row+1,column+1);
			}
			else return;
		}
		//弹出分配等级的 窗口
		public function setLevel(evt:MouseEvent):void{
			//Alert.show("分配等级");
			var setLevelui:LevelSet = new LevelSet();
			PopUpManager.addPopUp(setLevelui,this);
			setLevelui.x = 200;
			setLevelui.y = this.y - setLevelui.height;
			if(setLevelui.y < 0)
				setLevelui.y = 0;
			setLevelui.addEventListener("levelSetEvent",onLevelSet);
		}
		
		public function onLevelSet(evt:Event):void{
			//Alert.show("test");
			//Alert.show(evt.target.levelListUI.selectedIndex + "");
			if(this.index <= 10){
				this.level = evt.target.levelListUI.selectedIndex + 1;
				
				img.load(new URLRequest(ChessMain.IMGDIR1 + ( (index-1)%5+1 ) + ChessMain.imgArr[level]));
			}
			
		}
		//判断棋子规则
		//判断棋子规则
		private function passJudge(decury:DecuryMan,column:int,row:int):Boolean
		{
			if(decury.row==row&&decury.col==column)
				return false;	
			else if(ChessMain.terrian[row][column]<0||ChessMain.mapArr[row][column]>100)
				return false;
			else if(decury.row==row)
			{
				if(Math.abs(decury.col-column)>1)
				{
					if(decury.isCross==false) return false;
					for(var i:uint=Math.min(decury.col,column)+1;i<Math.max(decury.col,column);i++)
					{
						if(0!=ChessMain.mapArr[row][i])						
							return false;
						switch (ChessMain.terrian[row][i])
						{
							case 1:return false;break;
							case -1:return false;break;
							case 2:if(decury.level<0)return false;break;
							case 3:if(decury.level>0)return false;break;
							case -2:if(decury.level<0)return false;break;
							case -3:if(decury.level>0)return false;break;
						}
					}
					if(0!=ChessMain.mapArr[row][column])
					{
						if(ChessMain.mapArr[row][column]*decury.level>0)
							return true	;											//形成棋堆
						else
						{
							if(decury.isCrossAttack)
								return true;
							else return false;
						}
					}
					else
						return true;
				}
				else
				{			
					return true;
				}
			}
			else if(decury.col==column)
			{
				if(Math.abs(decury.row*10+decury.col-row*10-column)>10)
				{
					if(decury.isCross==false) return false;
					for(var i:uint=Math.min(decury.row,row)+1;i<Math.max(decury.row,row);i++)
					{
						if(0!=ChessMain.mapArr[i][column])
							return false;
						switch (ChessMain.terrian[i][column])
						{
							case 1:return false;break;
							case -1:return false;break;
							case 2:if(decury.level<0)return false;break;
							case 3:if(decury.level>0)return false;break;
							case -2:if(decury.level<0)return false;break;
							case -3:if(decury.level>0)return false;break;
						}
					}
					if(0!=ChessMain.mapArr[row][column])
					{
						if(ChessMain.mapArr[row][column]*decury.level>0)
							return true	;											//形成棋堆
						else
						{
							if(decury.isCrossAttack)
								return true;
							else return false;
						}
					}
					else
						return true;
					
				}
				else
				{			
					return true;
				}
			}
			else if(Math.abs(decury.row-row)==Math.abs(decury.col-column))
			{
				//					mx.controls.Alert.show(Math.abs((row*10+column)-(decury.row*10+decury.column))+" ")
				if(Math.abs((row*10+column)-(decury.row*10+decury.col))%9==0)
				{
					if(Math.abs((row*10+column)-(decury.row*10+decury.col))==9) 
					{
						if(column<decury.col)
						{
							if(ChessMain.terrian[decury.row+1][decury.col]<0&&ChessMain.terrian[decury.row][decury.col-1]<0)
							{
								switch(ChessMain.terrian[decury.row+1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level<0)return false;break;
									case -3:if(decury.level>0)return false;break;
								}
							}	
							return true;
						}
						else
						{
							if(ChessMain.terrian[decury.row-1][decury.col]<0&&ChessMain.terrian[decury.row][decury.col+1]<0)
							{
								switch(ChessMain.terrian[decury.row-1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level<0)return false;break;
									case -3:if(decury.level>0)return false;break;
								}
							}
							return true;
						}
					}
					else
					{
						if(decury.isBias==false) return false;
						var min:uint=Math.min((row*10+column),(decury.row*10+decury.col));
						var max:uint=Math.max((row*10+column),(decury.row*10+decury.col));
						if(ChessMain.terrian[(uint)((min-1)/10)][(uint)((min-1)%10)]<0&&ChessMain.terrian[(uint)((min+10)/10)][(uint)((min+10)%10)])
						{
							switch(ChessMain.terrian[(uint)((min-1)/10)][(uint)((min-1)%10)])
							{
								case -1:return false;break;
								case -2:if(decury.level<0)return false;break;
								case -3:if(decury.level>0)return false;break;
							}
						}
						for(var i:uint=min+9;i<max;i+=9)
						{//mx.controls.Alert.show("min"+min+"  "+"max"+max+"  "+(uint)(i/10)+"  "+i%10);
							if(0!=ChessMain.mapArr[(uint)(i/10)][i%10])
								return false;
							switch (ChessMain.terrian[(uint)(i/10)][i%10])
							{
								case 1:return false;break;
								case -1:return false;break;
								case 2:if(decury.level<0)return false;break;
								case 3:if(decury.level>0)return false;break;
								case -2:if(decury.level<0)return false;break;
								case -3:if(decury.level>0)return false;break;
							}
							if(ChessMain.terrian[(uint)((i+10)/10)][i%10]<0&&ChessMain.terrian[(uint)(i/10)][(i-1)%10]<0)
							{
								switch(ChessMain.terrian[(uint)((i+10)/10)][i%10])
								{
									case -1:return false;break;
									case -2:if(decury.level<0)return false;break;
									case -3:if(decury.level>0)return false;break;
								}
							}
							
						}
						if(0!=ChessMain.mapArr[row][column])
						{
							if(ChessMain.mapArr[row][column]*decury.level>0)
								return true	;											//形成棋堆
							else
							{
								if(decury.isBiasAttack)
									return true;
								else return false;
							}
						}
						else
							return true;
					}
				}
				if(Math.abs((row*10+column)-(decury.row*10+decury.col))%11==0)
				{
					if(Math.abs((row*10+column)-(decury.row*10+decury.col))==11) 
					{
						if(column<decury.col)
						{
							if(ChessMain.terrian[decury.row-1][decury.col]<0&&ChessMain.terrian[decury.row][decury.col-1]<0)
							{
								switch(ChessMain.terrian[decury.row-1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level<0)return false;break;
									case -3:if(decury.level>0)return false;break;
								}
							}	
							return true;
						}
						else
						{
							if(ChessMain.terrian[decury.row+1][decury.col]<0&&ChessMain.terrian[decury.row][decury.col+1]<0)
							{
								switch(ChessMain.terrian[decury.row+1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level<0)return false;break;
									case -3:if(decury.level>0)return false;break;
								}
							}
							return true;
						}						
					}
					else
					{
						if(decury.isBias==false) return false;
						var min:uint=Math.min((row*10+column),(decury.row*10+decury.col));
						var max:uint=Math.max((row*10+column),(decury.row*10+decury.col));
						if(ChessMain.terrian[(uint)((min+1)/10)][(uint)((min+1)%10)]<0&&ChessMain.terrian[(uint)((min+10)/10)][(uint)((min+10)%10)])
						{
							switch(ChessMain.terrian[(uint)((min+1)/10)][(uint)((min+1)%10)])
							{
								case -1:return false;break;
								case -2:if(decury.level<0)return false;break;
								case -3:if(decury.level>0)return false;break;
							}
						}
						for(var i:uint=min+11;i<max;i+=11)
						{
							if(0!=ChessMain.mapArr[(uint)(i/10)][i%10])
								return false;
							switch (ChessMain.terrian[(uint)(i/10)][i%10])
							{
								case 1:return false;break;
								case -1:return false;break;
								case 2:if(decury.level<0)return false;break;
								case 3:if(decury.level>0)return false;break;
								case -2:if(decury.level<0)return false;break;
								case -3:if(decury.level>0)return false;break;
							}
							if(ChessMain.terrian[(uint)((i+10)/10)][i%10]<0&&ChessMain.terrian[(uint)(i/10)][(i+1)%10]<0)
							{
								switch(ChessMain.terrian[(uint)((i+10)/10)][i%10])
								{
									case -1:return false;break;
									case -2:if(decury.level<0)return false;break;
									case -3:if(decury.level>0)return false;break;
								}
							}
						}
						if(0!=ChessMain.mapArr[row][column])
						{
							if(ChessMain.mapArr[row][column]*decury.level>0)
								return true	;											//形成棋堆
							else
							{
								if(decury.isBiasAttack)
									return true;
								else return false;
							}
						}
						else
							return true;
						
					}
				}
			}
			else return false;
			return false;
		}
		
		private function showGreenPoints(decury:DecuryMan):void
		{
			for(var i:int=0;i<100;i++)
			{
				var greenPointRow:int=i/10;
				var greenPointCol:int=i%10;
				
				if(passJudge(decury,greenPointCol,greenPointRow))
				{
					parent.addChild(ChessMain.greenPoints[greenPointRow][greenPointCol]);
				}
			}
		}
		
		
		public function addDrag():void{
			//开始拖到事件
			this.addEventListener(MouseEvent.MOUSE_DOWN, drag);
			//停止拖动事件
			this.addEventListener(MouseEvent.MOUSE_UP,updrag);
		}
		
		public function drag(evt:MouseEvent):void{
			parent.addChild(this);
			//this.z = 100;
			var startX:int = x;
			var startY:int = y;
			this.startDrag();  
		}
		
		//停止拖动，把棋子放在正确的位置
		public function updrag(evt:MouseEvent):void{
			this.stopDrag();
			this.x = ChessMain.showPos.x;
			this.y = ChessMain.showPos.y;
		}
		
		public function load(url:URLRequest):void{
			img.load(url);
			this.addChild(img);
		}
		
		public function reset():void{
			img.load(new URLRequest(ChessMain.IMGDIR1 + ((index-1)%5+1) + "Ab.png"));
			this.level = 0;
		}
		
		public function removeDrag():void{
			//开始拖到事件
			this.removeEventListener(MouseEvent.MOUSE_DOWN, drag);
			//停止拖动事件
			this.removeEventListener(MouseEvent.MOUSE_UP,updrag);
		}
		
		//开始可以移动棋子
		public function startMove():void{
			this.addEventListener(MouseEvent.CLICK, click);
			
			this.addEventListener(MouseEvent.MOUSE_DOWN,down);
			this.addEventListener(MouseEvent.MOUSE_UP,up);
		}
		
		
	}
}